package com.zgm.ch04._7_2;

public final class Complex {
	
	private double re;
	private double im;
	
	public Complex(Double re, Double im) {
		super();
		if(re != null){
			this.re = re;
		}
		if(im != null){
			this.im = im;
		}
		
	}
	/*public Double getRe() {
		return re;
	}
	public Double getIm() {
		return im;
	}*/
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("(").append(this.re);
		if(this.im > 0){
			sb.append("+");
		}
		
		sb.append(this.im).append(")");
		
		return sb.toString();
	}
	
	public Complex add(Complex complex){
		return new Complex(this.re + complex.re, //re为为private 为什么能通过complex.re调用？
				this.im + complex.im);
	}

}
